﻿using Digitalmes.Domain.Entities.Mes.Processes;

namespace Digitalmes.Application.Mes.Processes.Operations.Commands;

/// <summary>
/// 更新工序命令。
/// </summary>
/// <param name="Operation"></param>
public record UpdateOperationCommand(ProcOperationDto Operation) : IRequest<IResult<bool>>;

internal sealed class UpdateOperationCommandHandler(IRepository<ProcOperation> repo) : IRequestHandler<UpdateOperationCommand, IResult<bool>>
{
    public async Task<IResult<bool>> Handle(UpdateOperationCommand request, CancellationToken cancellationToken)
    {
        var operation = request.Operation.Adapt<ProcOperation>();
        var ok = await repo.UpdateAsync(operation, m => new
        {
            m.OpName,
            m.LineId,
            m.LineCode,
            m.Workstations,
            m.Esop,
            m.Classify,
            m.ProcessTypeCode,
            m.ProcessTypeName,
            m.Status,
        }, cancellationToken);
        return Result.From(ok);
    }
}
